using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSRI.HelperClasses;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Xml;
using System.IO;
using Instedd.Labs.Geo.Library.Kml;

namespace Instedd.Labs.Geo.Library.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class LatLongFixture
    {
        public LatLongFixture()
        {}

        [TestMethod]
        public void EqualsReturnsTrueIfTwoLatLongObjectHaveSameLatAndLongValues()
        {
            LatLong latLong1 = new LatLong(11.22, 33.44);
            LatLong latLong2 = new LatLong(11.22, 33.44);
            LatLong latLong3 = new LatLong(11.55, 33.66);

            Assert.AreEqual(latLong1, latLong2);
            Assert.AreNotEqual(latLong1, latLong3);
            Assert.AreNotEqual(latLong1, new object());
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void OutOfRangeLatLongShouldThrow()
        {
            // invalid Lat
            LatLong latLong1 = new LatLong(-100, 20);

            // invalid Long
            LatLong latLong2 = new LatLong(50, -200);

            // invalid Lat & Long
            LatLong latLong3 = new LatLong(500, 600);
        }

        [TestMethod]
        public void LatLongDecimalStringsParsingCreatesLatLongInstance()
        {
            LatLong latLong1 = LatLong.Parse("50", "-20");
            LatLong latLong2 = new LatLong(50, -20);
            Assert.AreEqual(latLong1, latLong2);

            LatLong latLong3 = LatLong.Parse("-80 170");
            LatLong latLong4 = new LatLong(-80, 170);
            Assert.AreEqual(latLong3, latLong4);
        }

        [TestMethod]
        public void LatLongDMSStringsParsingCreatesLatLongInstance()
        {
            LatLong latLong = LatLong.Parse("37.28.39.79 122.9.2.13");

            Assert.IsNotNull(latLong);
            Assert.AreEqual(37.477719, latLong.Lat);
            Assert.AreEqual(122.150592, latLong.Long);
        }

        [TestMethod]
        public void NegativeLatLongDMSStringsParsingCreatesLatLongInstance()
        {
            LatLong latLong = LatLong.Parse("-37.28.39.79 -122.9.2.13");

            Assert.IsNotNull(latLong);
            Assert.AreEqual(-37.477719, latLong.Lat);
            Assert.AreEqual(-122.150592, latLong.Long);
        }

        [TestMethod]
        public void LatLongDMSStringsParsingWithoutMinutesDecimalsCreatesLatLongInstance()
        {
            LatLong latLong = LatLong.Parse("37.28.39 122.9.2");
            
            Assert.IsNotNull(latLong);
            Assert.AreEqual(37.4775, latLong.Lat);
            Assert.AreEqual(122.150556, latLong.Long);
        }
    }
}